using Microsoft.SemanticKernel;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;
using OpenAI;
//兼容OpenAI的服务注册器
public class OpenAiCompatibleRegister : AiProviderRegister
{
    public override EnumAiProviderType AiProviderType => EnumAiProviderType.OpenAI_Compatible;

    protected override void RegisterChatCompletionService(IKernelBuilder builder, IServiceProvider provider, AiProvider aiProvider)
    {
        var modelId = aiProvider.GetChatCompletionApiService()?.ModelId;
        if (string.IsNullOrWhiteSpace(modelId))
        {
            return;
        }
        var clientOPtions = new OpenAIClientOptions
        {
            Endpoint = new Uri(aiProvider.ApiEndpoint)
        };
        var client = new OpenAIClient(new ApiKeyCredential(aiProvider.ApiKey), clientOPtions);
        builder.AddOpenAIChatCompletion(modelId: modelId, openAIClient: client);
    }

    [Experimental("SKEXP0010")]
    protected override void RegisterEmbeddingService(IKernelBuilder builder, IServiceProvider provider, AiProvider aiProvider)
    {
        var modelId = aiProvider.GetChatCompletionApiService()?.ModelId;
        if (string.IsNullOrWhiteSpace(modelId))
        {
            return;
        }
        var clientOPtions = new OpenAIClientOptions
        {
            Endpoint = new Uri(aiProvider.ApiEndpoint)
        };
        var client = new OpenAIClient(new ApiKeyCredential(aiProvider.ApiKey), clientOPtions);

        builder.AddOpenAIEmbeddingGenerator(modelId, openAIClient: client);
    }
}